package com.aboo.action;

import com.aboo.api.EmployeeService;
import com.aboo.domain.Employee;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/consumer")
public class ConsumerEmployeeAction {

    @Reference(group = "enterprise", version = "1.0")
    private EmployeeService employeeService01;
    @Reference(group = "enterprise", version = "1.1")
    private EmployeeService employeeService02;

    @RequestMapping("/employee01")
    public Map<String, Object> employee01() {
        Map<String, Object> result = new HashMap<>(8);
        result.put("flag", "Y");
        result.put("desc", "这是一个dubbo消费者1.0测试");

        Employee queryEmployee = employeeService01.getById(1039L);

        queryEmployee.setId(3876L);
        employeeService01.saveEmployee(queryEmployee);

        result.put("data", queryEmployee);
        log.info(JSONObject.toJSONString(result));

        return result;
    }

    @RequestMapping("/employee02")
    public Map<String, Object> employee02() {
        Map<String, Object> result = new HashMap<>(8);
        result.put("flag", "Y");
        result.put("desc", "这是一个dubbo消费者1.1测试");

        Employee queryEmployee = employeeService02.getById(2456L);

        queryEmployee.setId(4896L);
        employeeService02.saveEmployee(queryEmployee);

        result.put("data", queryEmployee);
        log.info(JSONObject.toJSONString(result));

        return result;
    }

}
